package com.sobot.finance.poc.web.controller;

import com.sobot.finance.poc.web.controller.base.BaseController;
import com.sobot.finance.poc.web.controller.request.GeneralReq;
import com.sobot.finance.poc.web.controller.response.GeneralRes;
import com.sobot.finance.poc.web.entity.BatchData;
import com.sobot.finance.poc.web.entity.TaskStatus;
import com.sobot.finance.poc.web.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 外呼任务上报
 *
 * @author baiyp
 */
@RestController
@Slf4j
public class TaskController extends BaseController {

    @Resource
    private TaskService taskService;

    /**
     * 按逾期天数对应不同模板创建任务(POC阶段客户方只用一种场景编码)
     *
     * @param req 请求参数
     * @return
     */
    @RequestMapping(value = "/poc/batchTask", method = RequestMethod.POST)
    public GeneralRes batchTask(@RequestBody GeneralReq<BatchData> req) {
        log.info("[批次外呼任务上报-开始]: {}", gson.toJson(req));
        GeneralRes res = taskService.batchTask(req.getData(), false);
        log.info("[批次外呼任务上报-结束]: {}", gson.toJson(req));
        return res;
    }

    @RequestMapping(value = "/poc/task/status", method = RequestMethod.POST)
    public GeneralRes status(@RequestBody GeneralReq<TaskStatus> req) {
        log.info("[批量外呼任务状态修改-开始]: {}", gson.toJson(req));
        GeneralRes res = taskService.optBatchTask(req.getData());
        log.info("[批量外呼任务状态修改-结束]: {}", gson.toJson(req));
        return res;
    }

    @RequestMapping(value = "/manual/batchTask", method = RequestMethod.POST)
    public GeneralRes manualBatchTask(@RequestBody GeneralReq<BatchData> req) {
        log.info("[批次外呼任务上报-开始]: {}", gson.toJson(req));
        GeneralRes res = taskService.batchTask(req.getData(), true);
        log.info("[批次外呼任务上报-结束]: {}", gson.toJson(req));
        return res;
    }
}
